/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bifang.gwt.client;

import han.bifang.gwt.client.app.ApplicationTab;
import han.bifang.gwt.client.common.Content;
import han.bifang.gwt.client.common.GwtContext;
import han.bifang.gwt.client.communicate.BifangGWTServiceAsync;
import han.bifang.gwt.client.config.ConfigTab;
import han.bifang.gwt.client.domain.DomainTab;
import han.bifang.gwt.client.logout.LogoutTab;
import han.bifang.gwt.client.sec.SecurityTab;
import han.bifang.gwt.client.service.ServiceTab;
import han.bifang.gwt.client.stat.StatTab;

import com.google.gwt.user.client.ui.SourcesTabEvents;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * 
 * @Author Kent
 */
public class MainPanel extends Content {
	private CatalogMessages constants = null;
	private GwtContext context = null;
	private BifangGWTServiceAsync service;
	private ServiceTab serviceTab;
	private VerticalPanel vPanel;
	
	public MainPanel(CatalogMessages constants, BifangGWTServiceAsync service1,
			GwtContext ctx) {
		this.context = ctx;
		this.service = service1;
		this.constants = constants;
		
		vPanel = new VerticalPanel();
		vPanel.setWidth("100%");
		vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_LEFT);
		initWidget(vPanel);

	}
	
	public void onLoad(){

		
		
		TabPanel tabs = new TabPanel() {
			public boolean onBeforeTabSelected(SourcesTabEvents sender,
					int tabIndex) {
				if (tabIndex == 2)
					serviceTab.init();
				return true;
			}
		};
		tabs.setWidth("100%");

		
		DomainTab domaintab = new DomainTab(service, context);
		domaintab.setWidth("100%");

		tabs.add(domaintab, constants.domainMgmt());
		tabs.selectTab(0);

		ApplicationTab appTab = new ApplicationTab(service, context);
		appTab.setWidth("100%");

		tabs.add(appTab, constants.appMgmt());

		serviceTab = new ServiceTab(service, context);
		serviceTab.setWidth("100%");
		tabs.add(serviceTab, constants.serviceMgmt());

		SecurityTab secTab = new SecurityTab(service, context);
		secTab.setWidth("100%");
		tabs.add(secTab, constants.securityMgmt());

		StatTab logTab = new StatTab(service, context);
		logTab.setWidth("100%");
		tabs.add(logTab, constants.logMgmt());
		
		ConfigTab configTab = new ConfigTab(service , context);
		configTab.setWidth("100%");
		tabs.add(configTab, constants.configMgmt());
		
		LogoutTab logoutTab = new LogoutTab(service, context);
		logoutTab.setWidth("50%");
		logoutTab.setContentChangeListener(this.listener);
		tabs.add(logoutTab,constants.logout());
		
		vPanel.add(tabs);
		
	}
	
}
